﻿using System;
using System.Text;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TeamDeploy.Tasks.Tests
{
    /// <summary>
    /// Summary description for UninstallTests
    /// </summary>
    [TestClass]
    public class UninstallTests
    {
        [TestMethod]
        public void UninstallExecute()
        {

            Uninstall task = new Uninstall();

            task.BuildEngine = new MockBuild();
            task.ProductCode = "{307C4598-DB0E-431B-9688-8FC4EED163D4}";
            task.RemoteExecutePathFilename = "c:\\pstools\\psexec.exe";
            task.TargetMachine = Environment.MachineName;

            Assert.IsTrue(task.Execute(), "Execute Failed");
            Assert.IsFalse(Utility.IsInstalled("InstallUninstallTests", Environment.MachineName), "Product did not uninstall");

        }

        [TestMethod]
        public void UninstallByProductName()
        {
            Deploy deploy = new Deploy();
            List<string> uninstallList = deploy.GetUninstallProductCodes("InstallUninstallTests", Environment.MachineName);

            if (uninstallList != null && uninstallList.Count > 0)
            {
                foreach (string code in uninstallList)
                {
                    Uninstall uninstallTask = new Uninstall();
                    uninstallTask.BuildEngine = new MockBuild();
                    uninstallTask.ProductCode = code;
                    uninstallTask.RemoteExecutePathFilename = "c:\\pstools\\psexec.exe";
                    uninstallTask.TargetMachine = Environment.MachineName;
                    bool uninstallResult = uninstallTask.Execute();

                    Assert.IsTrue(uninstallResult, "Execute Failed");
                    Assert.IsFalse(Utility.IsInstalled("InstallUninstallTests", Environment.MachineName), "Product did not uninstall");

                }
            }
        }
     }
}
